home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / cexpress / files / adsubdir.asm next >
Encoding:
Assembly Source File  |  1989-05-03  |  3.3 KB  |  111 lines

  1. ;unsigned short  add_subdirectory(tree_array,position,name);
  2. ;  char  *tree_array,*name;
  3. ;  unsigned short  position;
  4.  
  5.     EXTRN  _memory_model:byte
  6.     EXTRN  _error_code:byte
  7.     EXTRN  _tree_array_size:word
  8.  
  9. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  10.     ASSUME CS:_TEXT
  11.     PUBLIC _add_subdirectory
  12. _add_subdirectory proc near
  13.     push bp            ;
  14.     mov  bp,sp        ;
  15.     push di            ;
  16.     push si            ;
  17.     jmp  short start    ;jump over local data
  18. array_address dd ?        ;
  19. start:    cmp  _memory_model,0    ;near or far?
  20.     jle  begin        ;jump if near
  21.     inc  bp            ;else add 2 to BP
  22.     inc  bp            ;
  23. begin:    push ds            ;
  24.     cmp  _memory_model,2    ;data near or far?
  25.     jb   L0            ;jump if near
  26.     les  di,dword ptr[bp+4]    ;get tree array address
  27.     add  di,21        ;start with array element 1
  28.     mov  word ptr cs:array_address,di 
  29.     mov  word ptr cs:array_address+2,es
  30.     mov  bx,[bp+8]        ;get Position
  31.     lds  si,dword ptr[bp+10];DS:SI pts to Name
  32.     jmp  short L00        ;
  33. L0:    mov  ax,[bp+4]        ;NEAR case
  34.     add  ax,21        ;start with array element 1
  35.     mov  word ptr cs:array_address,ax
  36.     mov  word ptr cs:array_address+2,ds
  37.     mov  bx,[bp+6]        ;get Position
  38.     mov  si,[bp+8]        ;Name
  39. L00:    mov  dh,1        ;1 = Position out of range
  40.     mov  ax,_tree_array_size ;fetch _tree_array_size
  41.     inc  _tree_array_size    ;will add a record
  42.     cmp  bx,ax        ;in range?
  43.     ja   L6            ;quit if not
  44.     inc  dh            ;2 = Name is null string
  45.     sub  cx,cx        ;must get string length
  46.     push si            ;
  47. L1:    cmp  byte ptr[si],0    ;end of string?
  48.     je   L2            ;
  49.     inc  cx            ;inc counter
  50.     inc  si            ;inc pointer
  51.     jmp  short L1        ;
  52. L2:    pop  si            ;now length in CX
  53.     jcxz L6            ;quit if null
  54.     mov  dh,0        ;0 = no error
  55.     push ax            ;save position of new record
  56.     les  di,dword ptr cs:array_address ;DS:DI pts to tree array
  57.     mov  dl,21        ;21 bytes per record
  58.     mul  dl            ;AX = offset of new record
  59.     add  di,ax        ;point ES:DI to new record
  60.     push di            ;save record ptr
  61.     inc  cx            ;move terminating null also
  62.     cld            ;
  63.     rep  movsb        ;copy Name to record
  64.     pop  di            ;restore record ptr
  65.     mov  es:[di+13],bx    ;set Parent field
  66.     mov  es:[di+15],cx    ;set Child to "none"
  67.     mov  es:[di+19],cx    ;set Next to "none"
  68.     lds  si,dword ptr cs:array_address ;now DS:SI pts to tree array
  69.     mov  ax,bx        ;move Position
  70.     dec  ax            ;count from zero
  71.     cmp  ax,0ffffh        ;test for root directory case
  72.     jne  L3            ;jump if not root
  73.     mov  ax,1        ;start with first record
  74.     jmp  short L4        ;jump ahead
  75. L3:    mov  dl,21        ;bytes per record
  76.     mul  dl            ;
  77.     add  si,ax        ;point to parent record
  78.     mov  ax,[si+15]        ;get Child from parent
  79.     or   ax,ax        ;see if child exists?
  80.     jz   L5            ;jump if not
  81. L4:    mov  bx,ax        ;copy record number
  82.     dec  ax            ;count records from zero
  83.     lds  si,dword ptr cs:array_address ;reload array address
  84.     mov  dl,21        ;bytes per record
  85.     mul  dl            ;    
  86.     add  si,ax        ;
  87.     mov  ax,[si+19]        ;test for next child
  88.     or   ax,ax        ;
  89.     jnz  L4            ;loop till find last child
  90.     mov  word ptr es:[di+17],bx ;set new record's Prior
  91.     pop  ax            ;position of new record
  92.     inc  ax            ;count from 1
  93.     mov  [si+19],ax        ;set Next field of Prior
  94.     jmp  short L6        ;
  95. L5:    mov  word ptr es:[di+17],0 ;set new record's Prior to 0
  96.     pop  ax            ;position of new record
  97.     inc  ax            ;count from 1
  98.     mov  [si+15],ax        ;set Child field of Parent
  99. L6:    pop  ds            ;
  100.     mov  _error_code,dh    ;set _error_code
  101.     pop  si            ;
  102.     pop  di            ;
  103.     pop  bp            ;
  104.     cmp  _memory_model,0    ;quit
  105.     jle  quit        ;
  106.     db   0CBh        ;RET far
  107. quit:    ret            ;RET near
  108. _add_subdirectory  endp
  109. _TEXT    ENDS
  110.     END
  111.